﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Country.aspx.cs" Inherits="FastTravel.IntranetWeb.Country" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
	<title>Список стран</title>
	 <ext:XScript ID="xScript" runat="server">
		<Script type="text/javascript">
			var clearFilter = function () {
				#{txtFilterCountryName}.reset();
				#{txtFilterCountryCode}.reset();
				#{grdCountry}.getStore().clearFilter();
			}
		</Script>
	</ext:XScript>
</head>
<body>
	<form id="formCountry" runat="server">
	<ext:ResourceManager ID="resourceManager" runat="server" Theme="Gray" DirectMethodNamespace="FastTravel.IntranetWeb"/>
	<ext:GridPanel ID="grdCountry" runat="server" Title="Страны" AutoHeight="true" StripeRows="true" AutoExpandColumn="Name">
			<Store>
				<ext:Store ID="StoreCountry" runat="server" OnRefreshData="StoreRefresh" RemoteSort="true">
					<Proxy>
					   <ext:PageProxy />
					</Proxy>
					<Reader>
						<ext:JsonReader IDProperty="ID" TotalProperty="total">
							<Fields>
								<ext:RecordField Name="ID" Type="Int"/>
								<ext:RecordField Name="Name" Type="String" SortDir="ASC"/>
								<ext:RecordField Name="Code" Type="String" />
								<ext:RecordField Name="ISO" Type="String" />
							</Fields>
						</ext:JsonReader>
					</Reader>
					<BaseParams>
						<ext:Parameter Name="start" Value="0" Mode="Raw" />
						<ext:Parameter Name="limit" Value="10" Mode="Raw" />
						<ext:Parameter Name="sort" Value="Name" />
						<ext:Parameter Name="dir" Value="ASC" />
					</BaseParams>
					<SortInfo Field="Name" Direction="ASC" />
				</ext:Store>
			</Store>
			<TopBar>
				<ext:Toolbar runat="server" ID="toolBar" Height="30">
					<Items>
						<ext:Button ID="btтAddCountry" runat="server" Text="Новая страна"  Icon="Add">
							<DirectEvents>
									<Click OnEvent="BtnAddCountryClick" >
									</Click>
							</DirectEvents>
						</ext:Button>
					</Items>
				</ext:Toolbar>
			</TopBar>
			<ColumnModel ID="columnCountries" runat="server">
				<Columns>
					<ext:Column ColumnID="ID" Header="№" Width="40" DataIndex="ID" Hidden="true"/>
					<ext:Column Header="Название" Width="200" DataIndex="Name"/>
					<ext:Column Header="Код" Width="50" DataIndex="Code" />
					<ext:Column Header="ISO" Width="50" DataIndex="ISO" />

					<ext:CommandColumn Width="55" Header="Действ.">
					                                         
					   <Commands>                                               
						  <ext:GridCommand CommandName="Edit" Icon="Pencil" ToolTip-Text="Изменить">                                                        
						  </ext:GridCommand>
						  <ext:GridCommand CommandName="Delete" Icon="Cross" ToolTip-Text="Удалить">
						  </ext:GridCommand>
					   </Commands>
					</ext:CommandColumn>
					
					<ext:Column Width="28" DataIndex="ID" Sortable="false" MenuDisabled="true" Header="&nbsp;" Fixed="true">
						<Renderer Handler="return '';" />
					</ext:Column>

					<ext:Column Width="28" DataIndex="ID" Sortable="false" MenuDisabled="true" Header="&nbsp;" Fixed="true">
						<Renderer Handler="return '';" />
					</ext:Column>

				</Columns>
			</ColumnModel>
			<DirectEvents>                                        
				<Command OnEvent="GridAction" Buffer="250">
					<EventMask ShowMask="true" />
						<ExtraParams>
							<ext:Parameter Name="command" Value="command" Mode="Raw"/>
							<ext:Parameter Name="id" Value="record.id" Mode="Raw"/>
						</ExtraParams>
						<Confirmation BeforeConfirm="if (command=='Edit') return false;" ConfirmRequest="true" Message="Вы хотите удалить страну?" Title="Удаление страны" />
				</Command>
			</DirectEvents>
			<View>
				<ext:GridView ID="grdFilter" runat="server">
					<HeaderRows>
						<ext:HeaderRow>
							<Columns>
								<ext:HeaderColumn/>
								<ext:HeaderColumn>
									<Component>
										<ext:TextField runat="server" ID="txtFilterCountryName" AllowBlank="true" SelectOnFocus="true">
											<DirectEvents>
												<SpecialKey Before="return e.getKey() == Ext.EventObject.ENTER;" OnEvent="BtnSearchCountryClick"/>
											</DirectEvents>
										</ext:TextField>
									</Component>
								</ext:HeaderColumn>
								
								<ext:HeaderColumn>
									<Component>
										<ext:TextField runat="server" ID="txtFilterCountryCode" AllowBlank="true" SelectOnFocus="true">
											<DirectEvents>
												<SpecialKey Before="return e.getKey() == Ext.EventObject.ENTER;" OnEvent="BtnSearchCountryClick"/>
											</DirectEvents>
										</ext:TextField>
									</Component>
								</ext:HeaderColumn>
								
								<ext:HeaderColumn/>
								<ext:HeaderColumn/>
								
								<ext:HeaderColumn>
									<Component>
										<ext:Button runat="server" ID="btnFilterAdd" Icon="Find" >
											<ToolTips>
												<ext:ToolTip ID="tipFindData" runat="server" Html="Поиск" />
											</ToolTips>
											<DirectEvents>
												<Click OnEvent="BtnSearchCountryClick" />
											</DirectEvents>
										</ext:Button>
									</Component>
								</ext:HeaderColumn>

								<ext:HeaderColumn AutoWidthElement="false">
									<Component>
										<ext:Button ID="ClearFilterButton" runat="server" Icon="Cancel">
											<ToolTips>
												<ext:ToolTip ID="tipClearFilter" runat="server" Html="Очистить фильтр" />
											</ToolTips>
											 
											<Listeners>
												<Click Handler="clearFilter(null);" />
											</Listeners>                                            
										</ext:Button>
									</Component>
								</ext:HeaderColumn>

							</Columns>
						</ext:HeaderRow>
					</HeaderRows>
				</ext:GridView>
			</View>	
			<BottomBar>
				<ext:PagingToolbar ID="toolbarBottomPaging" runat="server" BeforePageText="Страница" AfterPageText="из" PageSize="10" DisplayInfo="true" DisplayMsg="Страны {0} - {1} из {2}      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" EmptyMsg="Нет стран"  LabelAlign="Left">
					<Items>
						<ext:Label ID="lblPageSize" runat="server" Text="Размер страницы:" />
						<ext:ToolbarSpacer ID="toolbarSpacer" runat="server" Width="10"/>
						<ext:ComboBox ID="comboPageSize" runat="server" Width="50">
							<Items>
								<ext:ListItem Text="10" />
								<ext:ListItem Text="15" />
								<ext:ListItem Text="20" />
								<ext:ListItem Text="30" />
								<ext:ListItem Text="50" />
							</Items>
							<SelectedItem Value="10" />
							<Listeners>
								<Select Handler="#{toolbarBottomPaging}.pageSize = parseInt(this.getValue()); #{toolbarBottomPaging}.doLoad();" />
							</Listeners>
						</ext:ComboBox>
					</Items>
				</ext:PagingToolbar>
			</BottomBar>
			<SelectionModel>
						<ext:RowSelectionModel ID="RowSelectionModel" runat="server" SingleSelect="true">
						</ext:RowSelectionModel>
			</SelectionModel>
			<LoadMask ShowMask="true" Msg="Загрузка данных о странах..."/>
			<SaveMask ShowMask="true" Msg="Сохранение данных о странах..."/>
		</ext:GridPanel>
		
		<!-- New country window -->

		<ext:Window ID="winCountryNew" runat="server" Icon="Add" Width="400" Modal="true" Hidden="true" Layout="Fit" AutoHeight="true" Title="Добавление страны" >
			<Items>
				<ext:FormPanel ID="pnlCountryNew" runat="server" Padding="5"	Layout="Form" AutoWidth="true" AutoHeight="true">
					<Items>
						<ext:TextField runat="server" ID="txtCountryNameNew" AllowBlank="false" FieldLabel="Название" />
						<ext:TextField runat="server" ID="txtCountryCodeNew" FieldLabel="Код" />
						<ext:NumberField runat="server" ID="txtCountryISONew" MinValue="0" Text="0" FieldLabel="ISO код"/>
					</Items>
					<Buttons>
						<ext:Button ID="btnAddNew" runat="server" Text="Добавить" Icon="Accept" >
							<DirectEvents>
									<Click OnEvent="BtnConfirmNewCountry" />
							</DirectEvents>
							<Listeners>
								<Click Handler=" 
									canSubmit = false; 
									#{pnlCountryNew}.items.each( 
									function(item) { canSubmit = item.validate();  if(!canSubmit) breack;
									}); return canSubmit;  " />
							</Listeners>
						</ext:Button>
						<ext:Button ID="btnCancelNew" runat="server" Text="Отменить" Icon="Decline" >
							<Listeners>
								<Click Handler="#{winCountryNew}.hide();" />
							</Listeners>
						</ext:Button>
					</Buttons>
				</ext:FormPanel>
			</Items>
		</ext:Window>

		<!-- Edit country window -->

		<ext:Window ID="winCountryEdit" runat="server" Icon="VcardEdit" Width="400" Modal="true" Hidden="true" Layout="Fit" AutoHeight="true" Title="Редактирование страны" >
			<Items>
				<ext:FormPanel ID="pnlCountryEdit" runat="server" Padding="5"	Layout="Form" AutoWidth="true" AutoHeight="true">
					<Items>
						<ext:TextField runat="server" ID="txtCountryNameEdit" AllowBlank="false" FieldLabel="Название" />
						<ext:TextField runat="server" ID="txtCountryCodeEdit" FieldLabel="Код" />
						<ext:NumberField runat="server" ID="txtCountryISOEdit" MinValue="0" Text="0" FieldLabel="ISO код"/>
					</Items>
					<Buttons>
						<ext:Button ID="btnCountryEdit" runat="server" Text="Сохранить" Icon="Disk" >
							<DirectEvents>
									<Click OnEvent="BtnConfirmEditCountry" />
							</DirectEvents>
							<Listeners>
								<Click Handler=" 
									canSubmit = false; 
									#{pnlCountryEdit}.items.each( 
									function(item) { canSubmit = item.validate();  if(!canSubmit) breack;
									}); return canSubmit;  " />
							</Listeners>
						</ext:Button>
						<ext:Button ID="btnCancelEdit" runat="server" Text="Отменить" Icon="Decline" >
							<Listeners>
								<Click Handler="#{winCountryEdit}.hide();" />
							</Listeners>
						</ext:Button>
					</Buttons>
				</ext:FormPanel>
			</Items>
		</ext:Window>
	</form>
</body>
</html>
